package com.zrwl.poscloud.xo.service.impl;
import com.zrwl.poscloud.base.entity.UserBlack;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrwl.poscloud.base.enums.EStatus;
import com.zrwl.poscloud.base.superI.SuperServiceImpl;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.utils.StringUtils;
import com.zrwl.poscloud.xo.global.MessageConf;
import com.zrwl.poscloud.xo.global.SQLConf;
import com.zrwl.poscloud.xo.global.SysConf;
import com.zrwl.poscloud.xo.mapper.GradeMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import com.zrwl.poscloud.xo.mapper.UserBlackMapper;
import com.zrwl.poscloud.xo.service.UserBlackService;
import com.zrwl.poscloud.xo.vo.UserBlackVO;

import javax.annotation.Resource;

/**
 * 黑名单 服务实现类
 *
 * @author 刘思童 AutoGenerate
 * @date 2023-02-27
 */
@Service
public class UserBlackServiceImpl extends SuperServiceImpl<UserBlackMapper,UserBlack> implements UserBlackService {

    @Autowired
    private UserBlackService userBlackService;
    @Resource
    private UserBlackMapper userBlackMapper;
    @Override
    public IPage<UserBlackVO> getPageList(UserBlackVO userBlackVO){
       Page<UserBlack> page = new Page<>();
       page.setCurrent(userBlackVO.getCurrentPage());
       page.setSize(userBlackVO.getPageSize());
       IPage<UserBlackVO> pageList = userBlackMapper.getPageList(page, userBlackVO);
       List<UserBlackVO> list = pageList.getRecords();
       pageList.setRecords(list);
       return pageList;
}
    @Override
    public List<UserBlack> getAllList(UserBlackVO userBlackVO){
        QueryWrapper<UserBlack> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne(SQLConf.STATUS, EStatus.DISABLED);
        queryWrapper.orderByAsc(SQLConf.CREATE_TIME);
        List<UserBlack> list = userBlackService.list(queryWrapper);
        return list;
}
    @Override
    public String add(UserBlackVO userBlackVO){
        UserBlack userBlack = userBlackMapper.getBlackByUser(userBlackVO.getUserUid(),userBlackVO.getType());
        if(userBlack != null){
            throw new RuntimeException("该用户已加入黑名单");
        }
        UserBlack entity = new UserBlack();
        BeanUtils.copyProperties(userBlackVO, entity, SysConf.STATUS);
        entity.insert();
        userBlackVO.setUid(entity.getUid());
        return ResultUtil.successWithMessage(MessageConf.INSERT_SUCCESS);}
    @Override
    public String edit(UserBlackVO userBlackVO){
        UserBlack entity = userBlackService.getById(userBlackVO.getUid());
        BeanUtils.copyProperties(userBlackVO, entity);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
    @Override
    public String delete(UserBlackVO userBlackVO){
        UserBlack entity = userBlackService.getById(userBlackVO.getUid());
        entity.setStatus(EStatus.DISABLED);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
}
